<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
    <title>注册</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 55px;
            position: relative; /* 让我们可以定位侧边 */
        }
        .register-form {
            max-width: 400px;
            margin: auto;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #f9f9f9;
        }
        .register-form input[type="text"],
        .register-form input[type="email"],
        .register-form input[type="password"] {
            width: 90%;
            padding: 10px;
            margin: 10px 0;
        }
        .register-form input[type="submit"] {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        .register-form input[type="submit"]:hover {
            background-color: #0056b3;
        }
        .error {
            color: red;
            text-align: center;
            margin-top: 10px;
        }
        .password-requirements {
            font-size: 0.9em;
            color: #555;
            margin-top: 5px;
            display: none; /* 默认隐藏 */
        }
        .toggle-requirements {
            position: absolute; /* 绝对定位 */
            top: 50%; /* 垂直居中 */
            left: 100%; /* 靠右侧 */
            transform: translateY(-50%); /* 垂直居中 */
            cursor: pointer;
            color: pink; /* 粉色 */
            text-decoration: underline;
            margin-left: 10px; /* 距离注册框一些空间 */
        }
        .toggle-requirements:hover {
            color: #ff69b4; /* 浅粉色 */
        }
    </style>
</head>
<body>
<div class="register-form">
    <h2>注册</h2>
    <form action="${pageContext.request.contextPath}//RegisterServlet" method="post">
        <input type="text" name="username" placeholder="用户名" required>
        <input type="text" name="nickname" placeholder="昵称" required>
        <input type="email" name="email" placeholder="邮箱" required>
        <input type="password" name="password" placeholder="密码" title="密码需大于7位，可包含字母、数字和特殊字符！" required>

        <!-- 显示或隐藏密码要求的链接 -->
        <div class="toggle-requirements" onclick="toggleRequirements()">查看密码要求</div>

        <div class="password-requirements" id="requirements">
            密码需大于7位，可使用以下字符：
            <ul>
                <li>大写字母（A-Z）</li>
                <li>小写字母（a-z）</li>
                <li>数字（0-9）</li>
                <li>特殊字符（如 !@#$%^&*()_+）</li>
            </ul>
        </div>

        <input type="password" name="confirmPassword" placeholder="确认密码" title="请再次输入密码" required>
        <input type="text" name="invitationCode" placeholder="邀请码（可选）">
        <input type="submit" value="注册">
    </form>
    <%
        String error = (String) request.getAttribute("error");
        if (error != null) {
    %>
    <div class="error"><%= error %></div>
    <%
        }
    %>
</div>

<!-- 添加 JavaScript 代码 -->
<script>
    function toggleRequirements() {
        const requirements = document.getElementById("requirements");
        if (requirements.style.display === "none") {
            requirements.style.display = "block"; // 显示
        } else {
            requirements.style.display = "none"; // 隐藏
        }
    }
</script>
</body>
</html>